package com.vo;


import lombok.Data;
import org.apache.catalina.Context;
import org.apache.catalina.LifecycleException;
import org.apache.catalina.connector.Connector;
import org.apache.catalina.startup.Tomcat;

import javax.servlet.*;
import java.io.IOException;
import java.util.Scanner;

@Data
public class Demo {

    private String name;
    private Integer age;

    public Demo(String name,Integer age){
        this.name=name;
        this.age=age    ;
    }

    public static void main(String[] args) throws LifecycleException {
        Tomcat tomcat=new Tomcat()  ;
        Connector connector=new Connector();
        connector.setPort(8080);
        connector.setURIEncoding("UTF-8");
        tomcat.getService().addConnector(connector);
//        tomcat上下文
        Context context = tomcat.addContext("context", null);
//        编写一些Servlet 注册进入tomcat上下文
        tomcat.addServlet(context, "servlet", new Servlet() {
            @Override
            public void init(ServletConfig servletConfig) throws ServletException {

            }

            @Override
            public ServletConfig getServletConfig() {
                return null;
            }

            @Override
            public void service(ServletRequest servletRequest, ServletResponse servletResponse) throws ServletException, IOException {

                System.out.println("进入方法");
            }

            @Override
            public String getServletInfo() {
                return null;
            }

            @Override
            public void destroy() {

            }
        });
        //拦截路径
        context.addServletMappingDecoded("/doServlet","servlet");
        tomcat.start();
        tomcat.getServer().await();
    }

}
